// server.js
const express = require('express');
const fs = require('fs');
const feather = require('feather-format');
const app = express();
const port = 3000;

app.get('/data', (req, res) => {
    fs.readFile('./feather/stock/stock_codes.feather', (err, data) => {
        if (err) {
            console.error('Error reading file:', err);
            res.status(500).send('Error reading file.');
            return;
        }
        feather.parse(data, { columns: null }, (err, dataframe) => {
            if (err) {
                console.error('Error parsing feather data:', err);
                res.status(500).send('Error parsing feather data.');
                return;
            }
            // 将DataFrame转换为JSON
            const jsonData = JSON.stringify(dataframe);
            res.send(jsonData);
        });
    });
});

app.listen(port, () => {
    console.log(`Server running at http://localhost:${port}/`);
});
